#include<stdio.h>
int main()
{
    int a,n[7],m[7],x[7],y[7],k1=0,k2=0;
    long s1[7],s2[7],s[7];
    scanf("%d",&a);
    for(int i=0;i<a-1;i++)
    {
        scanf("%d %d %d %d",&n[i],&m[i],&x[i],&y[i]);
        s[i]=0;
w1:
        s1[i]=k1*n[i]+m[i];
        s2[i]=k2*x[i]+y[i];
        if(s1[i]>s2[i])
        {
            k2=k2+1;
            goto w1;
        }
        else if(s2[i]>s1[i])
        {
            k1=k1+1;
            goto w1;
        }
        else if(s1[i]==s2[i])
        {
            s[i]=s1[i];
        }
        k1=0;k2=0;
    }
    for(int k=0;k<a-1;k++)
    {
        printf("%ld",s[k]);
    }
}
